package com.bjsxt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bjsxt.domain.InventoryLog;
import com.bjsxt.dto.InventoryLogDto;
import com.bjsxt.mapper.InventoryLogMapper;
import com.bjsxt.service.InventoryLogService;
import com.bjsxt.vo.DataGridView;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 批次库存及价格service接口实现类
 */
@Service
public class InventoryLogServiceImpl implements InventoryLogService {

    @Autowired
    private InventoryLogMapper inventoryLogMapper;

    /**
     * 分页查询批次库存及价格
     *
     * @param inventoryLogDto
     * @return
     */
    @Override
    public DataGridView listInventoryLogPage(InventoryLogDto inventoryLogDto) {
        Page<InventoryLog> page = new Page<>(inventoryLogDto.getPageNum(), inventoryLogDto.getPageSize());
        QueryWrapper<InventoryLog> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNotBlank(inventoryLogDto.getPurchaseId()), InventoryLog.COL_PURCHASE_ID, inventoryLogDto.getPurchaseId());
        queryWrapper.like(StringUtils.isNotBlank(inventoryLogDto.getMedicinesName()), InventoryLog.COL_MEDICINES_NAME, inventoryLogDto.getMedicinesName());
        queryWrapper.eq(StringUtils.isNotBlank(inventoryLogDto.getMedicinesType()), InventoryLog.COL_MEDICINES_TYPE, inventoryLogDto.getMedicinesType());
        queryWrapper.eq(StringUtils.isNotBlank(inventoryLogDto.getPrescriptionType()), InventoryLog.COL_PRESCRIPTION_TYPE, inventoryLogDto.getPrescriptionType());
        queryWrapper.eq(StringUtils.isNotBlank(inventoryLogDto.getProducterId()), InventoryLog.COL_PRODUCTER_ID, inventoryLogDto.getProducterId());
        queryWrapper.eq(StringUtils.isNotBlank(inventoryLogDto.getPrescriptionType()), InventoryLog.COL_PRESCRIPTION_TYPE, inventoryLogDto.getPrescriptionType());
        queryWrapper.ge(inventoryLogDto.getBeginTime() != null, InventoryLog.COL_CREATE_TIME, inventoryLogDto.getBeginTime());
        queryWrapper.le(inventoryLogDto.getEndTime() != null, InventoryLog.COL_CREATE_TIME, inventoryLogDto.getEndTime());
        queryWrapper.orderByDesc(InventoryLog.COL_CREATE_TIME);
        this.inventoryLogMapper.selectPage(page, queryWrapper);
        return new DataGridView(page.getTotal(), page.getRecords());
    }
}
